const Sequelize = require('sequelize')
const db = require('./db')
// 将allowNull设置为false会将NOT NULL添加到列中，
const WxUser = db.define('wx_user', {
  open_id: { type: Sequelize.STRING(100), primaryKey: true, allowNull: false },
  uuid: { type: Sequelize.STRING(100), allowNull: false },
  skey: { type: Sequelize.STRING(100), allowNull: false },
  create_time: { type: Sequelize.DATE, defaultValue: Sequelize.NOW, allowNull: false },
  last_visit_time: { type: Sequelize.DATE, defaultValue: Sequelize.NOW, allowNull: false },
  session_key: { type: Sequelize.STRING(100), allowNull: false },
  user_info: {type: Sequelize.STRING(2048), allowNull: false}

}, {
  // 如果为 true 则表的名称和 model 相同，即 user
  // 为 false MySQL创建的表名称会是复数 users
  // 如果指定的表名称本就是复数形式则不变
  // freezeTableName: true,
  timestamps: false
})
WxUser.sync({ force: false })
  .then(res => {
    console.log('create table successfully!')
  })
  .catch(err => {
    console.log('create table error!', err)
  })
module.exports = WxUser
